package com.ruoyi.web.controller.member.service.Impl;

import com.ruoyi.common.entity.DO.member.MemberDO;
import com.ruoyi.common.entity.DO.member.MemberVipTypeDO;
import com.ruoyi.common.entity.VO.member.MemberVipTypeSearchVO;
import com.ruoyi.common.entity.VO.member.MemberVipTypeVO;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.web.controller.member.mapper.IBackMemberVipTypeMapper;
import com.ruoyi.web.controller.member.service.IBackMemberVipTypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BackMemberVipTypeServiceImpl implements IBackMemberVipTypeService {

    @Resource
    private IBackMemberVipTypeMapper memberVipTypeMapper;

    @Override
    public List<MemberVipTypeVO> searchList(MemberVipTypeSearchVO searchVO) {
        return memberVipTypeMapper.searchList(searchVO);
    }

    @Override
    public void edit(MemberVipTypeVO memberVipTypeVO) {
        MemberVipTypeDO memberVipTypeInfo = memberVipTypeMapper.selectByPrimaryKey(memberVipTypeVO.getId());
        if(memberVipTypeInfo == null){
            throw new BusinessException("没找到该会员等级！");
        }
        if(null != memberVipTypeVO.getUpgradeValue()){
            memberVipTypeInfo.setUpgradeValue(memberVipTypeVO.getUpgradeValue());
        }
        if(null != memberVipTypeVO.getUpgradeCondition()){
            memberVipTypeInfo.setUpgradeCondition(memberVipTypeVO.getUpgradeCondition());
        }
        if(null != memberVipTypeVO.getIsEnable()){
            memberVipTypeInfo.setIsEnable(memberVipTypeVO.getIsEnable());
        }
        if(null != memberVipTypeVO.getOrderNum()){
            memberVipTypeInfo.setOrderNum(memberVipTypeVO.getOrderNum());
        }
        memberVipTypeMapper.updateByPrimaryKeySelective(memberVipTypeInfo);
    }
}
